Skip to content

perf: optimize encode in datafusion-functions#23456

Merged
Dandandan merged 1 commit into
apache:mainfrom
andygrove:auto-opt/encode-2026-07-10-df-002
Jul 11, 2026
Merged

perf: optimize encode in datafusion-functions#23456
Dandandan merged 1 commit into
apache:mainfrom
andygrove:auto-opt/encode-2026-07-10-df-002

Conversation

@andygrove

@andygrove andygrove commented Jul 10, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

Rewrote the hex path of encode() to write hex directly into one pre-sized buffer via hex::encode_to_slice, eliminating a per-element String allocation and copy per row.

What changes are included in this PR?

Rewrote the hex path of encode() to write hex directly into one pre-sized buffer via hex::encode_to_slice, eliminating a per-element String allocation and copy per row.

Are these changes tested?

Existing tests

Benchmark:

  • hex_encode_1024: 80.934% faster (base 25305ns -> cand 4824ns)
  • hex_encode_4096: 81.297% faster (base 99386ns -> cand 18587ns)
  • hex_encode_8192: 80.24% faster (base 200031ns -> cand 39525ns)

Are there any user-facing changes?

No

@github-actions github-actions Bot added the functions Changes to functions implementation label Jul 10, 2026
@andygrove andygrove marked this pull request as ready for review July 10, 2026 17:45
@andygrove andygrove added the performance Make DataFusion faster label Jul 10, 2026
// The slice is sized to exactly `2 * v.len()`, which is the only
// condition under which `encode_to_slice` can fail, so this cannot
// error.
hex::encode_to_slice(v, &mut values[pos..pos + out_len])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i remember we did some work previously on having a faster hex encoding algorithm (iirc for Spark functions)

would that be applicable here too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I opened I opened #23473 to apply this pattern there to apply some of the same optimizations for Spark hex encoding.

@Dandandan Dandandan added this pull request to the merge queue Jul 11, 2026
Merged via the queue into apache:main with commit 5b60fcb Jul 11, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation performance Make DataFusion faster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants